package com.lagou.sqlSession;

import com.lagou.config.XMLconfigBuilder;
import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws PropertyVetoException, DocumentException {
        // 第一： 使用dom4j解析配置文件，将解析出来的内容封装到容器对象Configuration中
        XMLconfigBuilder xmlConfigBuilder = new XMLconfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);
        //第二： 创建sqlSessionFactory 对象: 生产sqlSession,会话对象。

        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return defaultSqlSessionFactory;
    }

}
